<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            title="同意退款"
            :async="true"
            width="550px"
            @confirm="handleSubmit"
            @close="handleClose"
        >
            <el-alert
                title="您同意退款后，退款将自动原路退回至买家付款账户"
                type="warning"
                :closable="false"
            />
            <el-form ref="formRef" :model="formData" label-width="120px">
                <el-form-item prop="type" label="售后类型"> {{ refund_method_desc }}</el-form-item>
                <el-form-item prop="type" label="申请退款金额">
                    ￥{{ apply_refund_amount }}</el-form-item
                >
                <el-form-item prop="type" label="退款金额">
                    <el-input
                        type="number"
                        v-model="formData.actual_refund_amount"
                        placeholder="请输入"
                        class="w-[180px]"
                    >
                        <template #append>元</template>
                    </el-input>
                </el-form-item>
                <el-form-item prop="type" label="团长佣金">
                    <el-radio-group v-model="formData.teamhead_earnings" class="ml-4">
                        <el-radio :label="1">佣金退还</el-radio>
                        <el-radio :label="2">佣金不退还</el-radio>
                    </el-radio-group>
                    <div class="form-tips">已结算佣金的订单,售后申请通过后退还佣金</div>
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import { aftersalerefund } from '@/api/order'

import Popup from '@/components/popup/index.vue'
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const route = useRoute()
const props = defineProps({
    refund_method_desc: {
        type: String
    },
    apply_refund_amount: {
        type: String
    }
})
const formData = reactive({
    id: route.query.id,
    actual_refund_amount: '',
    teamhead_earnings: 1
})

const open = () => {
    popupRef.value?.open()
}

const handleClose = () => {
    emit('close')
}

defineExpose({
    open
})
//提交
const handleSubmit = async () => {
    await aftersalerefund(formData)
    popupRef.value?.close()
    emit('success')
}
</script>
